package cn.util.baidu.service.impl;

import cn.util.baidu.service.BaiduUitlService;
import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONException;
import org.json.JSONObject;

public class BaiduUitlServiceImpl implements BaiduUitlService {

    //百度设置APPID/AK/SK
    public static final String APP_ID = "11225711";
    public static final String API_KEY = "ldt25aWoWCStNSFvU8Ycl7Gg";
    public static final String SECRET_KEY = "1uar3i71r42GQa06wS2OQFBD1qlVxsqO";


    /**
     * 百度图片审核
     * @param path
     * @return
     * @throws JSONException
     */
    public    String CheckTuPian(String path) throws JSONException{
        // 初始化一个AipImageCensor
        AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
        // 可选：设置网络连接参数
        // client.setConnectionTimeoutInMillis(2000);
        //client.setSocketTimeoutInMillis(60000);
        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
        //client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
        //client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 可选：设置log4j日志输出格式，若不设置，则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
        //System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
        // 调用接口
        JSONObject res = client.antiPorn(path);
        return res.get("conclusion").toString();

    }

}
